#pragma once

#define MINUS_ZERO	-0.0001
#define PLUS_ZERO	 0.0001

#include "primitive.h"
#include "texcoords.h"

class triangle: public primitive
{
public:

	point pointA;
	texcoords pointATexCoord;
	point pointB;
	texcoords pointBTexCoord;
	point pointC;
	texcoords pointCTexCoord;

	triangle();
	triangle(point cen, point cen1, point cen2, point cen3, double mul, const char* _name);
	triangle(point cen, point cen1, point cen2, point cen3, double mul);
	triangle(point cen, point cen1, point cen2, point cen3);
	triangle(point cen1, point cen2, point cen3, double mul, const char* _name);
	triangle(point cen1, point cen2, point cen3, double mul);
	triangle(point cen1, point cen2, point cen3, const char* _name);
	triangle(point cen1, point cen2, point cen3);
	triangle(point cen, vector3 vec1, vector3 vec2, double mul, const char* _name);
	triangle(point cen, vector3 vec1, vector3 vec2, double mul);
	triangle(point cen, vector3 vec1, vector3 vec2);

	~triangle();

	void getTriangleFromXML(std::ifstream &file);

	double maxX();
	double minX();
	double maxY();
	double minY();
	double maxZ();
	double minZ();

	void setATexCoords(texcoords tex);
	void setBTexCoords(texcoords tex);
	void setCTexCoords(texcoords tex);
	void setTexCoords(texcoords texA, texcoords texB, texcoords texC);

	void copyTriangle(triangle TheOneToCopyFrom);
	point getCenter();
	//material getMaterial();
	double getSurfaceArea();

	int intersect( ray& Ray, intersection& inter);
	bool planeIntersect(ray& Ray, point& colisionPoint);
	bool isInShade( ray& Ray);
	vector3 getNormal(point inPoint);
	void getTextureCoords(intersection& inter);
	
};